package work.coffee.connect;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.swing.JOptionPane;

public class CloserUtil {
	public static void close(Connection con) {
		if (con != null) {
			try {
				con.close();
			} catch (SQLException e) {
				JOptionPane.showMessageDialog(null, "SQL 정보가 존재하지 않음");
			} finally {
				con = null;
			}
		}
	}

	public static void close(PreparedStatement pstmt) {
		if (pstmt != null) {
			try {
				pstmt.close();
			} catch (SQLException e) {
				JOptionPane.showMessageDialog(null, "SQL 정보가 존재하지 않음");
			} finally {
				pstmt = null;
			}
		}
	}

	public static void close(ResultSet rs) {
		if(rs!=null){
			try {
				rs.close();
			} catch (SQLException e) {	
				JOptionPane.showMessageDialog(null, "SQL 정보가 존재하지 않음");
			} finally {
				rs = null;
			}
		}
	}
	
	public static void close(PreparedStatement pstmt, Connection con) {
				close(pstmt);
				close(con);			
	}
	
	public static void close(ResultSet rs, PreparedStatement pstmt, Connection con) {
		close(rs);
		close(pstmt, con);			
	}
}
